package com.dean.utils;

/**
 * @ClassName StringUtils
 * @Description 字符串工具类
 * @Author dean
 * @Date 2021/11/30 15:49
 */
public class StringUtils {

    public static boolean isBlank(String str){
        if(str == null || "".equals(str)){
            return true;
        }
        return false;
    }

    public static boolean isNotBlank(String str){
        return !isBlank(str);
    }

    public static String arrayToString(String [] array){
        return arrayToString(array,",");
    }

    public static String arrayToString(String [] array,String delimit){
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            stringBuilder.append(array[i]);
            if(i+1 < array.length){
                stringBuilder.append(delimit);
            }
        }
        return stringBuilder.toString();
    }

    public static String arrayToSqlVals(String [] array){
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < array.length; i++) {
            if(array[i]!=null){
                stringBuilder.append("'");
            }
            stringBuilder.append(array[i]);
            if(array[i]!=null){
                stringBuilder.append("'");
            }
            if(i+1<array.length){
                stringBuilder.append(",");
            }
        }
        return stringBuilder.toString();
    }

    /**
     * 替换字符串中的Unicode字符
     * @param text
     * @return
     */
    public static String replaceUnicodeChar2Blank(String text){
        if(StringUtils.isBlank(text)){
            return text;
        }
        return text.replaceAll("[\\x00-\\x08\\x0b-\\x0c\\x0e-\\x1f]", " ");
    }
}
